package com.wechatapp.mengyao.poetry.service.impl;

import com.wechatapp.mengyao.poetry.entity.ChinesePoetry;
import com.wechatapp.mengyao.poetry.entity.DailyPoetry;
import com.wechatapp.mengyao.poetry.mapper.DailyPoetryMapper;
import com.wechatapp.mengyao.poetry.service.DailyPoetryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.Date;

/**
 * @author yanghuaxu
 * @date 2025/6/19 13:01
 */
@Service
@Slf4j
public class DailyPoetryServiceImpl implements DailyPoetryService {

    @Autowired
    private DailyPoetryMapper dailyPoetryMapper;

    @Override
    public DailyPoetry getTodayPoetry() {
        DailyPoetry condition = new DailyPoetry();
        condition.setCreateDate(LocalDate.now());
        return dailyPoetryMapper.selectOne(condition);
    }

    @Override
    public ChinesePoetry getRandomPoetry() {
        return dailyPoetryMapper.getRandomPoetry();
    }

    @Override
    public int saveDailyPoetry(DailyPoetry p) {
        return dailyPoetryMapper.insertSelective(p);
    }
}
